<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/8
 * Time: 16:24
 */
require '../DbTools.php';

//根据session获取到用户名
session_start();
$key = $_COOKIE['userkey'];
$userName = '';
//根据$is_login判断是否要显示下面的内容（如头像内容）
$is_login = false;

//步骤：
//
//获取登录页面存储的卡号密码
//sql子查询 根据卡号密码找到银行卡表中的账户ID，根据账户ID找到账户信息表中的真实姓名
//获取结果集中的真实姓名赋值

if(!isset($_SESSION[$key])){
    $userName = "你尚未登录，<a href='/lession/login.php'>请登录</a>";
    }else{
    //获取用户名和密码
    $username = $_SESSION[$key]["username"];
    $psd = $_SESSION[$key]["psd"];
    //连接数据库
    DbTools::$conn=new mysqli('127.0.0.1','root','root','newBank');
    $sql="SELECT RealName 
    		from accountinfo 
    		WHERE AccountId=(select AccountId from bankcard WHERE CardNo='".$username."' and CardPwd='".$psd."')";
    $result=DbTools::select($sql);
    $userName='欢迎你 '.$result[0]["RealName"];
    $is_login = true;
}

$logUrl = '../public/image/'.$_GET['log'];
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <h3>用户中心</h3>
    <p><?php echo $userName;?></p>
    <?php if($is_login){?>
        <a href="changePwd_page.php">修改密码</a>
        <p>头像：<img src="<?php echo $logUrl;?>"></p>

        <form action="img.php" method="post" enctype="multipart/form-data">
            <input type="file" name="file">
            <br/>
            <button type="submit">上传头像</button>
        </form>
    <?php }?>

</body>

</html>

